#!/bin/bash

# Simple script to create end user credential resource file for use in our
# OpenStack environment

# Author K. Jackson

# ./create_novarc -u admin -p openstack -t admin -C $CC_ADDR


# Process Command Line
while getopts u:p:t:C: opts
do
  case $opts in
    u)
	KEYSTONE_USERNAME=${OPTARG}
        ;;
    p)
        KEYSTONE_PASSWORD=${OPTARG}
        ;;
    t)
        KEYSTONE_TENANT=${OPTARG}
        ;;
    C)
        API=${OPTARG}
        ;;
  esac
done

cat > ~/${KEYSTONE_USERNAME}rc << EOF
NOVA_API_HOST=$API
GLANCE_API_HOST=$API
KEYSTONE_API_HOST=$API

NOVA_REGION="nova"

export NOVA_USERNAME=$KEYSTONE_USERNAME
export NOVA_PROJECT_ID=$KEYSTONE_TENANT
export NOVA_PASSWORD=$KEYSTONE_PASSWORD
export NOVA_API_KEY=$KEYSTONE_PASSWORD
export NOVA_REGION_NAME=\$NOVA_REGION
export NOVA_URL="http://\$NOVA_API_HOST:5000/v2.0/"
export NOVA_VERSION="1.1"

export OS_AUTH_USER=$KEYSTONE_USERNAME
export OS_AUTH_KEY=$KEYSTONE_PASSWORD
export OS_AUTH_TENANT=$KEYSTONE_TENANT
export OS_AUTH_URL="http://\$KEYSTONE_API_HOST:5000/v2.0/"
export OS_AUTH_STRATEGY="keystone"

export EC2_URL="http://\$NOVA_API_HOST:8773/services/Cloud"
export EC2_ACCESS_KEY="$KEYSTONE_USERNAME:$KEYSTONE_TENANT"
export EC2_SECRET_KEY=$KEYSTONE_PASSWORD
export S3_URL="http://\$GLANCE_API_HOST:3333"
EOF
